package JDBCUI;

import javax.swing.*;
import javax.swing.JFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class MainForm extends JFrame {
    private JPanel root;
    private JButton loginButton;
    private JButton resetButton;
    private JTextField nameField;
    private JPasswordField passField;

    public JTextField getNameField() {

        return nameField;
    }


    public JPasswordField getPassField() {
        return passField;
    }


    public MainForm() {

        // 可以发现按钮和文本框都已经有了变化，给窗口润色不少。
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }catch(Exception e) {
            System.out.println(e);
        }

        resetButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
              JButton jButton=(JButton)  e.getSource();
               String text= jButton.getText();
              if ("重置".equals(text)){
                    getNameField().setText("");
                    getPassField().setText("");
              }
            }
        });
        loginButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JButton jButton=(JButton)  e.getSource();
                String text= jButton.getText();

                if ("登录".equals(text)){

                    System.out.println();
                    System.out.println("登录操作结束");
                }
                if(nameField.getText().equals("张三") && passField.getText().equals("123456") ){


                    JOptionPane.showMessageDialog(root,"登录成功");
                    new MainForm().dispose();
                MainJFrame mainJFrame = new MainJFrame();



                }else {
                    JOptionPane.showMessageDialog(root,"登录失败");
                }

                //JOptionPane.showMessageDialog(root,"Hello");




            }
        });



    }

    public static void main(String[] args) {

        JFrame frame = new JFrame("MainForm");
        frame.setContentPane(new MainForm().root);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600,500);
        frame.setVisible(true);






    }


}


